'''
Created on Nov 30, 2011

@author: anorberg
'''

import tsv
import csv
import os
import time

V1HEADER = [
            'FeatureA',
            'FeatureB',
            'TargetCol',
            'NResults',
            'KS',
            'Dispersion',
            'Unimodality',
            'BaseMean',
            'NewMean',
            'TotalMean',
            'Alarms',
            'BaseData',
            'NewData',
            'LogitBaseData',
            'LogitNewData'
            ]

V2SCHEMA = [
            ['Target', 'FeatureA'],
            ['Predictor', 'FeatureB'],
            'TargetCol',
            'NResults',
            'KS',
            'Dispersion',
            'Unimodality',
            'BaseMean',
            'NewMean',
            'TotalMean',
            'Alarms',
            'BaseData',
            'NewData',
            'LogitBaseData',
            'LogitNewData',
            'FlatDispersion',
            'FlatUnimodality'
            ]

CURRENTSCHEMA = [
            ['Target', 'FeatureA'],
            ['Predictor', 'FeatureB'],
            'TargetCol',
            'NResults',
            'KS',
            'FlatDispersion',
            'FlatUnimodality',
            'BaseMean',
            'NewMean',
            'TotalMean',
            'BaseData',
            'NewData'
            ]

V2HEADER = [
            'Target',
            'Predictor',
            'TargetCol',
            'NResults',
            'KS',
            'Dispersion',
            'Unimodality',
            'BaseMean',
            'NewMean',
            'TotalMean',
            'Alarms',
            'BaseData',
            'NewData',
            'LogitBaseData',
            'LogitNewData',
            'FlatDispersion',
            'FlatUnimodality'
            ]

V2V3SWITCH = time.strptime("5 Dec 2011", "%d %b %Y")
V2V3STAMP = time.mktime(V2V3SWITCH)

V3HEADER = [
            'Target',
            'Predictor',
            'TargetCol',
            'NResults',
            'KS',
            'FlatDispersion',
            'FlatUnimodality',
            'BaseMean',
            'NewMean',
            'TotalMean',
            'BaseData',
            'NewData',
            ]
def loadResultTable(filename):
    handle = open(filename, "r")
    #header = V2HEADER
    #if os.path.getctime(filename) > V2V3STAMP:
    #    header = V3HEADER
    header = V3HEADER
    return tsv.TsvReader(handle, CURRENTSCHEMA, header, dialect=csv.excel_tab, missingfill="00000")

